﻿Imports Mysoft.Map.Application.Security
Imports Mysoft.Map.Data
Imports Mysoft.PubProject.Business
Imports System.Data

Partial Public Class Desk_khgj
    Inherits Mysoft.Map.Application.Security.AppPage

    Protected strJrxgjcount, strYqwgjcount, strJqgsrcount, strDgjcount As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim strProjGUID, strBjType As String
        '初始值为0
        strJrxgjcount = "0"
        strYqwgjcount = "0"
        strJqgsrcount = "0"
        strDgjcount = "0"
        If Not IsPostBack Then
            If Not Request.QueryString("ProjGUID") Is Nothing Then
                strProjGUID = Request.QueryString("ProjGUID")
                strBjType = Request.QueryString("bjtype")
                Bind_Data(strProjGUID, strBjType)
            End If
        End If

    End Sub

    Private Sub Bind_Data(ByVal strProjGUID As String, ByVal strBjType As String)
        Dim strCusFilter, strWherePlan As String
        Dim dt As New DataTable
        Dim strAlterDays As String
        Dim strSQL As String
        Dim myBizParamMNG As New Mysoft.PubProject.Business.BizParamMNG
        '判断权限 
        strCusFilter = Mysoft.Slxt.Business.PublicMng.ZYHAuthorize(Session("UserGUID").ToString, "es_Opportunity", "01010210", "s_Opportunity")

        '今日需跟进统计、逾期未跟进统计、近3天过生日统计(置业顾问)
        strSQL = "Select IsNULL(sum(case when (DATEDIFF(D,s_Opportunity.NextDate,getdate())) = 0 then 1 else 0 end),0) as Jrxgjcount " & _
        ",  IsNULL(sum(case when (DATEDIFF(D,s_Opportunity.NextDate,getdate())) > 0 then 1 else 0 end),0) as Yqwgjcount" & _
        ",  IsNULL(sum(case when (DATEDIFF(dd,GETDATE(),DATEADD(Year,DATEDIFF(Year,p_Customer.BirthDate,GETDATE()),p_Customer.BirthDate)) BETWEEN 0 and 2) then 1 else 0 end),0) as Jqgsrcount " & _
        " From s_Opportunity inner join s_Opp2Cst on s_Opportunity.OppGUID = s_Opp2Cst.OppGUID and s_Opp2Cst.CstNum = 1 inner join p_Customer on s_Opp2Cst.CstGUID = p_Customer.CstGUID" & _
        " where s_Opportunity.Status <> '丢失'  and  ProjGUID in ('" & strProjGUID.Replace(",", "','") & "') and " & strCusFilter & ""
        dt = MyDB.GetDataTable(strSQL)
        If dt.Rows.Count > 0 Then
            strJrxgjcount = dt.Rows(0).Item("Jrxgjcount").ToString
            strYqwgjcount = dt.Rows(0).Item("Yqwgjcount").ToString
            strJqgsrcount = dt.Rows(0).Item("Jqgsrcount").ToString
        End If

        'If strBjType = "xsjl" Then
        strSQL = "Select Count(8) from s_Opportunity where ProjGUID in ('" & strProjGUID.Replace(",", "','") & "') and  DATEDIFF(DAY,NextDate,GETDATE()) <= 0 and NOT EXISTS(select * from s_Opp2Gjjl where GjrGUID = UserGUID and s_Opp2Gjjl.OppGUID = s_Opportunity.OppGUID) and s_Opportunity.Status <> '丢失' and " & strCusFilter & ""
        strDgjcount = MyDB.GetDataItemString(strSQL)
        'End If

    End Sub

End Class